﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Baosight.ZNH.ZMCommon;
using Baosight.Platform.Core;

namespace Baosight.ZNH.ZM.UI
{
    /// <summary>
    /// 首页-设备统计
    /// </summary>
    /// Title:ZM9R，ServiceZM9R
    /// Copyright:Baosight Software LTD.co Copyright (c) 2011
    /// Company:上海宝信软件股份有限公司
    /// Author: 高强
    /// Version: 1.0
    /// History:
    ///       2012-12-06  高强   [创建]
    ///
    public partial class ZM9F : EFViewCmes
    {
        public ZM9F()
        {
            InitializeComponent();

        }

        /// <summary>
        //初始化并渲染控件
        /// </summary>
        public override void Initialize(Baosight.Platform.Core.EIInfo initData)
        {
            base.Initialize(initData);
            EIBlock block = initData.GetBlock("result");
            for (int i = 0; i < block.GetRowCount(); i++)
            {
                IEnumerable<EIRow> zyResult = from c in block.GetRows() where c["useType"].ToString().Equals("在用") select c;
                if (zyResult.Count() > 0)
                {
                    ZY.Text = zyResult.First()["number"].ToString();
                }
                else
                {
                    ZY.Text = "0";
                }
                IEnumerable<EIRow> zkResult = from c in block.GetRows() where c["useType"].ToString().Equals("在库") select c;
                if (zkResult.Count() > 0)
                {
                    ZK.Text = zkResult.First()["number"].ToString();
                }
                else
                {
                    ZK.Text = "0";
                }
                IEnumerable<EIRow> fcResult = from c in block.GetRows() where c["useType"].ToString().Equals("封存") select c;
                if (fcResult.Count() > 0)
                {
                    FC.Text = fcResult.First()["number"].ToString();
                }
                else
                {
                    FC.Text = "0";
                }
                IEnumerable<EIRow> xzResult = from c in block.GetRows() where c["useType"].ToString().Equals("闲置") select c;
                if (xzResult.Count() > 0)
                {
                    XZ.Text = xzResult.First()["number"].ToString();
                }
                else
                {
                    XZ.Text = "0";
                }
                IEnumerable<EIRow> bfResult = from c in block.GetRows() where c["useType"].ToString().Equals("报废") select c;
                if (bfResult.Count() > 0)
                {
                    BF.Text = bfResult.First()["number"].ToString();
                }
                else
                {
                    BF.Text = "0";
                }
                IEnumerable<EIRow> dxResult = from c in block.GetRows() where c["useType"].ToString().Equals("待修") select c;
                if (dxResult.Count() > 0)
                {
                    DX.Text = dxResult.First()["number"].ToString();
                }
                else
                {
                    DX.Text = "0";
                }
                IEnumerable<EIRow> wxResult = from c in block.GetRows() where c["useType"].ToString().Equals("维修") select c;
                if (wxResult.Count() > 0)
                {
                    WX.Text = wxResult.First()["number"].ToString();
                }
                else
                {
                    WX.Text = "0";
                }

                HJ.Text = (Convert.ToInt32(ZY.Text) + Convert.ToInt32(ZK.Text) + Convert.ToInt32(FC.Text) + Convert.ToInt32(XZ.Text) + Convert.ToInt32(BF.Text) + Convert.ToInt32(DX.Text) + Convert.ToInt32(WX.Text)).ToString();     
            }
           this.PlanPieChart.ItemsSource = block.Rows;
        }

    }
}
